<?php

/**
 * This file is part of the Framework03 PHP framework.
 * @package Framework03
 * @author Walter Tamboer
 */

// Let's get the root directory, this will be useful when setting all the paths.
$root = dirname(dirname(__FILE__));

// The include paths so that all application items can be found.
set_include_path(get_include_path() . PATH_SEPARATOR . $root . '/../library');

// Make sure that PHP actually shows the errors.
ini_set('display_errors', true);

// Also make sure that PHP shows startup errors.
ini_set('display_startup_errors', true);

// We want to show all errors including strict errors because we don't make mistakes.
error_reporting(E_ALL | E_STRICT);

// We want automatic loading of classes because we're lazy.
require_once 'FW/Loader.php';
FW_Loader::startAutoLoading();

$uriList = array(
    'http://waltertamboer.nl',
    'http://waltertamboer.nl/mypage.php?name=Walter&age=21#anchorName',
    'ftp://waltertamboer.nl',
    'ftp://username:password@waltertamboer.nl',
    'ftp://username:password@waltertamboer.nl:1986/www/root/',
    'mailto:info@waltertamboer.nl',
    'mailto:info@waltertamboer.nl?subject=Hello World&body=Hi there',
);

foreach ($uriList as $uri)
{
    echo '<h3>' . $uri . '</h3>';

    try
    {
        $uri = FW_Uri::factory($uri);
        
        echo 'Link: <a href="' . $uri . '">' . $uri . '</a><br />';

        if (($uri instanceof FW_Uri_Http) || ($uri instanceof FW_Uri_Https))
        {
            echo 'Scheme: ' . $uri->getScheme() . '<br />';
            echo 'Username: ' . $uri->getUsername() . '<br />';
            echo 'Password: ' . $uri->getPassword() . '<br />';
            echo 'Host: ' . $uri->getHost() . '<br />';
            echo 'Port: ' . $uri->getPort() . '<br />';
            echo 'Path: ' . $uri->getPath() . '<br />';
            echo 'Query: ' . $uri->getQuery() . '<br />';
            echo 'Fragment: ' . $uri->getFragment() . '<br />';
        }
        else if (($uri instanceof FW_Uri_Ftp) || ($uri instanceof FW_Uri_Ftps))
        {
            echo 'Scheme: ' . $uri->getScheme() . '<br />';
            echo 'Username: ' . $uri->getUsername() . '<br />';
            echo 'Password: ' . $uri->getPassword() . '<br />';
            echo 'Host: ' . $uri->getHost() . '<br />';
            echo 'Port: ' . $uri->getPort() . '<br />';
            echo 'Path: ' . $uri->getPath() . '<br />';
        }
        else if ($uri instanceof FW_Uri_Mailto)
        {
            echo 'Scheme: ' . $uri->getScheme() . '<br />';
            echo 'To: ' . $uri->getTo() . '<br />';
            echo 'Host: ' . $uri->getHost() . '<br />';
            echo 'Headers: ' . $uri->getHeaders() . '<br />';
        }
    }
    catch (FW_Uri_Exception $e)
    {
        echo $e->getMessage();
    }
    
    echo '<hr />';
}
